import com.google.zxing.BarcodeFormat
import com.google.zxing.EncodeHintType
import com.google.zxing.MultiFormatWriter
import com.google.zxing.MatrixToImageWriter

import com.google.zxing.common.BitMatrix
import com.google.zxing.client.j2se.MatrixToImageWriter

final int w = 300
final int h = 300

String content= 'http://dy126.net/wx/auth'
String filePath = 'test.png'

Hashtable<EncodeHintType, String> hints = [:]
hints.put(EncodeHintType.CHARACTER_SET, 'UTF8')

BitMatrix bmx = new MultiFormatWriter().encode(content,
			BarcodeFormat.QR_CODE, w, h, hints)

MatrixToImageWriter.writeToFile(bmx, 'png', new File(filePath))
